﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace Heyo.Controls
{
    /// <summary>
    /// FloatingBar.xaml 的交互逻辑
    /// </summary>
    public class FloatHint_backup : ContentControl
    {
        public enum Direction
        {
            Top,
            Bottom,
            Left,
            Right
        }

        public static readonly DependencyProperty TipDirectionProperty = DependencyProperty.Register(
            "TipDirection", typeof(Direction), typeof(FloatHint_backup), new PropertyMetadata(Direction.Top));

        public Direction TipDirection
        {
            get => (Direction) GetValue(TipDirectionProperty);
            set => SetValue(TipDirectionProperty, value);
        }

        public static readonly DependencyProperty ShowHintProperty = DependencyProperty.Register(
            "ShowHint", typeof(bool), typeof(FloatHint_backup), new PropertyMetadata(default(bool)));

        public bool ShowHint
        {
            get => (bool) GetValue(ShowHintProperty);
            set => SetValue(ShowHintProperty, value);
        }

        static FloatHint_backup()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(FloatHint_backup), new FrameworkPropertyMetadata(typeof(FloatHint_backup)));
        }
        //public UIElementCollection Grid => grid.Children;
        public FloatHint_backup()
        {


            MouseEnter += (s, e) => { Show(); };
            Loaded += FloatHint_Loaded;
            VerticalAlignment = VerticalAlignment.Top;
            InitAnimation();

        }

        private void InitAnimation()
        {
            //MatrixAnim.RenderTransformOrigin = new Point(0.5, 0.5);
            //MatrixAnim.AnimFunction = new PowerEase() { Power = 4, EasingMode = EasingMode.EaseInOut };
            ////OpacityAnim.AnimFunction = new PowerEase() { Power = 2, EasingMode = EasingMode.EaseOut };
            //OpacityAnim.SpeedRatio = 4;
            //MatrixAnim.SpeedRatio = 4;
        }

        private void FloatHint_Loaded(object sender, RoutedEventArgs e)
        {
            ((FrameworkElement)Parent).MouseEnter += Parent_MouseEnter;
            ((FrameworkElement)Parent).MouseLeave += FloatHint_MouseLeave;
            //Margin = new Thickness(0, -ActualHeight - 8, 0, 0);
        }

        private void FloatHint_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Hide();
        }

        private void Parent_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Show();
        }

        ////public Thickness TipMargin
        ////{
        ////    get => TopTip.Margin;
        ////    set => TopTip.Margin = BottomTip.Margin = LeftTip.Margin = RightTip.Margin = value;
        ////}
        //private bool _isShow = false;
        public void Show()
        {
            ShowHint = true;
            //PreDirection();
            //MatrixAnim.BeginAnimation();
            //OpacityAnim.BeginAnimation();
        }
        public void Hide()
        {
            //if (!_isShow) return;
            //_isShow = false;
            //PreDirection();
            //MatrixAnim.BeginInverseAnimation();
            //OpacityAnim.BeginInverseAnimation();

            ShowHint = false;
        }
        //private void PreDirection()
        //{
        //    TopTip.Visibility = Visibility.Collapsed;
        //    BottomTip.Visibility = Visibility.Collapsed;
        //    LeftTip.Visibility = Visibility.Collapsed;
        //    RightTip.Visibility = Visibility.Collapsed;

        //    MatrixAnim.TransTo = new MatrixTransform(1, 0, 0, 1, 0, 0);

        //    switch (TipDirection)
        //    {
        //        default:
        //            {
        //                MatrixAnim.TransFrom = new MatrixTransform(0.75, 0, 0, 0.75, 0, -Height / 4);
        //                if (!ShowTip)
        //                    break;
        //                TopTip.Visibility = Visibility.Visible;
        //                break;
        //            }
        //        case Direction.Top:
        //            {
        //                MatrixAnim.TransFrom = new MatrixTransform(0.75, 0, 0, 0.75, 0, Height / 4);
        //                if (!ShowTip)
        //                    break;
        //                BottomTip.Visibility = Visibility.Visible;
        //                break;
        //            }
        //        case Direction.Bottom:
        //            {
        //                MatrixAnim.TransFrom = new MatrixTransform(0.75, 0, 0, 0.75, 0, -Height / 4);
        //                if (!ShowTip)
        //                    break;
        //                TopTip.Visibility = Visibility.Visible;
        //                break;
        //            }
        //        case Direction.Left:
        //            {
        //                MatrixAnim.TransFrom = new MatrixTransform(0.75, 0, 0, 0.75, Width / 4, 0);
        //                if (!ShowTip)
        //                    break;
        //                RightTip.Visibility = Visibility.Visible;
        //                break;
        //            }
        //        case Direction.Right:
        //            {
        //                MatrixAnim.TransFrom = new MatrixTransform(0.75, 0, 0, 0.75, -Width / 4, 0);

        //                if (!ShowTip)
        //                    break;
        //                LeftTip.Visibility = Visibility.Visible;
        //                break;
        //            }
        //    }

        //}
        //public Direction TipDirection { get; set; }
        //public bool ShowTip { get; set; } = true;
    }
}
